﻿using System.Collections.Generic;

using SharpArch.Core;
using SharpArch.Core.PersistenceSupport;
using SharpArch.Data.NHibernate;
using SharpArch.Testing.NUnit;
using SharpArch.Testing.NUnit.NHibernate;

using NUnit.Framework;

using Quiziqal.Domain;
using Quiziqal.Persistence;

namespace Quiziqal.Specifications.Persistence
{
    [TestFixture]
    public class when_creating_a_quiz : PersistenceTestBase
    {
        Quiz toDb;
        Quiz fromDb;
        User user;
        QuizRepository repository = new QuizRepository();

        protected override void EstablishContext()
        {
            user = CreatePersistedUser("arthur_dent");
            toDb = new Quiz(user);
        }

        protected override void Act()
        {
            repository.SaveOrUpdate(toDb);
            FlushSessionAndEvict(toDb);
            fromDb = repository.Get(toDb.ID);
        }

        [Test]
        public void retrieved_quiz_should_not_be_null()
        {
            fromDb.ShouldNotBeNull();
        }

        [Test]
        public void user_should_be_marked_as_owner()
        {
            fromDb.Owner.ShouldEqual(user);
            fromDb.Owner.ShouldNotBeTheSameAs(user);
        }
    }
}
